<template>
  <div class="history">
    <el-table :data="list" height="80vh" style="width: 100%">
      <el-table-column prop="title" label="新闻标题">
        <template slot-scope="scope">
          <el-link :underline="false" :href="'/news/' + scope.row.id">{{
            scope.row.title
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="最后浏览时间" width="200">
        <template slot-scope="scope">
          {{ scope.row.time }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="currentPage"
      :page-sizes="[10, 20, 50, 100]"
      :hide-on-single-page="pageHidden"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="len"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    ></el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      len: 100,
      limit: 10,
      currentPage: 1,
      value: true,
      list: []
    }
  },
  computed: {
    pageHidden() {
      return this.len < this.limit
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleSizeChange(val) {
      this.limit = val
      this.getList()
    },
    handleCurrentChange(page) {
      this.currentPage = page
      this.getList()
    },
    async getList() {
      const { status, data } = await this.$axios.get('/user/history', {
        params: {
          limit: this.limit,
          page: this.currentPage
        }
      })
      if (status === 200 && data.code === 1) {
        this.len = +data.len
        this.list = data.data
      }
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/ .el-table__body-wrapper {
  @include scroll();
}
</style>
